package com.lee.crawler.gov.strategy;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.safety.Whitelist;
import org.springframework.stereotype.Component;

@Component
public class FzcangshanArticleStrategy extends AbstractArticleStrategy {

	private static final DateTimeFormatter ofPattern = DateTimeFormatter.ofPattern("yyyy-MM-dd  HH:mm:ss");

	@Override
	public String getTitle(Document content) {
		return content.selectFirst(".zxft h3,h4").text();
	}

	@Override
	public Timestamp getPublishedTime(Document content) {
		String pubDate = content.selectFirst("meta[name=pubDate]").attr("content");
		LocalDateTime localDateTime = LocalDateTime.parse(pubDate, ofPattern);
		return Timestamp.valueOf(localDateTime);
	}

	@Override
	public String getContent(Document content) {
		return content.selectFirst("#detailCon,.TRS_Editor").text();
	}

	@Override
	public String getHtmlContent(Document content) {
		Element htmlContentEl = content.selectFirst("#detailCon,.TRS_Editor");
		String htmlContent = Jsoup.clean(htmlContentEl.html(), Whitelist.relaxed());
		return htmlContent;
	}

}
